function chunkUpload(file) {
    let fileMd5 = file.name + file.size + file.lastModified;
    $.ajax({
        url: '/checkMd5',
        type: 'GET',
        data: {"md5": fileMd5},
        success: function (res) {
            if (res) {
                const start = Number(res.data.fileSize);
                const taskId = res.data.taskId;
                if (res.data) {
                    upload(start, taskId, file);
                } else {
                    upload(0, taskId, file);
                }
            }
        },
        error: function (msg) {
            alert(msg);
        }
    })
}

function upload(start, taskId, file) {
    // 分片大小 5M
    const bytePercent = 1024 * 1024 * 5;
    // 通过文件大小除以分片大小得出总片数
    let totalChunks = Math.ceil(file.size / bytePercent);
    // 起始位置+分片数 如果大于文件大小，那么终点位置就是文件大小，反之就是前者
    let end = (start + bytePercent) > file.size ? file.size : (start + bytePercent);
    let fileName = file.name;
    // 分片文件
    let chunkFile = file.slice(start, end);
    // 当前分片数
    let currChunkNum = (start / bytePercent) + 1;
    let formData = new FormData();
    formData.append('file', chunkFile);
    formData.append("fileName", fileName);
    formData.append("fileSize", start);
    formData.append("taskId", taskId);
    formData.append("chunkNumber", currChunkNum);
    formData.append("chunkSize", bytePercent);
    formData.append("totalChunks", totalChunks);

    $.ajax({
        type: 'POST',
        url: '/chunkUpload',
        data: formData,
        // dataType: 'application/json',
        contentType: false,//很重要，指定为false才能形成正确的Content-Type
        processData: false,	//加入这属性    processData默认为true，为true时，提交不会序列化data。
        success: function (res) {
            if (res.data.result === '上传完毕') {
                alert("分片上传完成");
            } else {
                upload(end, taskId, file);
            }
        }
    });
}